package com.cat.bean.common;


public class PageBean {
	private String pageSize;
	private String totalRows;
	private String totalPages;
	private String currentRows;
	private String currentPage;
	
	public String getPageSize() {
		return pageSize;
	}
	public void setPageSize(String pageSize) {
		this.pageSize = pageSize;
	}
	public String getTotalRows() {
		return totalRows;
	}
	public void setTotalRows(String totalRows) {
		this.totalRows = totalRows;
	}
	public String getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(String totalPages) {
		this.totalPages = totalPages;
	}
	public String getCurrentRows() {
		return currentRows;
	}
	public void setCurrentRows(String currentRows) {
		this.currentRows = currentRows;
	}
	public String getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}
	public void initPaginationForPortal(){
		this.setCurrentRows("0");
		this.setPageSize(String.valueOf(Constant.pageSizeForPortal));
	}
	public void initPagination(String totalRows) {
		this.setTotalRows(totalRows);
		this.setCurrentRows("0");
		this.setCurrentPage("1");
		this.setTotalPages(getTotalPages(totalRows));
		this.setPageSize(String.valueOf(Constant.pageSize));
	}
	
	public void setPagination(String totalRows) {
		this.setTotalPages(getTotalPages(totalRows));
		int currentPage = Integer.parseInt(this.getCurrentPage());
		int currentRows = (currentPage-1) * Constant.pageSize;
		this.setCurrentRows(String.valueOf(currentRows));
		this.setPageSize(String.valueOf(Constant.pageSize));
	}
	
	private String getTotalPages(String totalRows) {
		String totalPages = "0";
		int ttRs = Integer.parseInt(totalRows);
		int ps = Constant.pageSize;
		if(ttRs % ps == 0) {
			totalPages = String.valueOf(ttRs / ps);
		}else {
			totalPages = String.valueOf(ttRs / ps + 1);
		}

		return totalPages;
	}	
}
